/**
 * admui-basic v2.1.0 (http://www.admui.com/)
 * Copyright 2015-2019 Admui Team
 * Licensed under the Admui License 1.1 (http://www.admui.com/about/license)
 */
(function(document, window, $) {
  'use strict';

  var slideIndex;
  var filtered;

  // Slick - 显示单个
  $('#exampleSingleItem').slick();

  // Slick - 显示多个
  $('#exampleMultipleItems').slick({
    infinite: true,
    slidesToShow: 3,
    slidesToScroll: 3
  });

  // Slick - 响应式
  $('#exampleResponsive').slick({
    dots: true,
    infinite: false,
    speed: 500,
    slidesToShow: 4,
    slidesToScroll: 4,
    responsive: [
      {
        breakpoint: 1024,
        settings: {
          slidesToShow: 3,
          slidesToScroll: 3,
          infinite: true,
          dots: true
        }
      },
      {
        breakpoint: 600,
        settings: {
          slidesToShow: 2,
          slidesToScroll: 2
        }
      },
      {
        breakpoint: 480,
        settings: {
          slidesToShow: 1,
          slidesToScroll: 1
        }
      }
    ]
  });

  // Slick - 可变宽度
  $('#exampleVariableWidth').slick({
    dots: true,
    infinite: true,
    speed: 300,
    slidesToShow: 1,
    centerMode: true,
    variableWidth: true
  });

  // Slick - 可变高度
  $('#exampleAdaptiveHeight').slick({
    dots: true,
    infinite: true,
    speed: 300,
    slidesToShow: 1,
    adaptiveHeight: true
  });

  // Slick - 通过Data属性设置
  $('#exampleData').slick();

  // Slick - 居中
  $('#exampleCenter').slick({
    centerMode: true,
    centerPadding: '60px',
    slidesToShow: 3,
    responsive: [
      {
        breakpoint: 768,
        settings: {
          arrows: false,
          centerMode: true,
          centerPadding: '40px',
          slidesToShow: 3
        }
      },
      {
        breakpoint: 480,
        settings: {
          arrows: false,
          centerMode: true,
          centerPadding: '40px',
          slidesToShow: 1
        }
      }
    ]
  });

  // Slick - 懒加载
  $('#exampleLazy').slick({
    lazyLoad: 'ondemand',
    slidesToShow: 3,
    slidesToScroll: 1
  });

  // Slick - 自动播放
  $('#exampleAutoplay').slick({
    dots: true,
    infinite: true,
    speed: 500,
    slidesToShow: 3,
    slidesToScroll: 1,
    autoplay: true,
    autoplaySpeed: 2000
  });

  // Slick - 渐变
  $('#exampleFade').slick({
    dots: true,
    infinite: true,
    speed: 500,
    fade: true,
    slide: 'div',
    cssEase: 'linear'
  });

  // Slick - 添加 & 删除
  slideIndex = 1;

  $('#exampleAddRemove').slick({
    dots: true,
    slidesToShow: 3,
    speed: 500,
    slidesToScroll: 3
  });

  // 添加操作
  $('#exampleAddSlide').on('click', function() {
    slideIndex += 1;
    $('#exampleAddRemove').slick('slickAdd', '<div><h3>' + slideIndex + '</h3></div>');
  });

  // 删除操作
  $('#exampleRemoveSlide').on('click', function() {
    $('#exampleAddRemove').slick('slickRemove', slideIndex - 1);
    if (slideIndex > 0) {
      slideIndex -= 1;
    }
  });

  // Slick - 过滤
  $('#exampleFiltering').slick({
    slidesToShow: 4,
    slidesToScroll: 4
  });

  filtered = false;

  // 点击过滤按钮
  $('#exampleFilter').on('click', function() {
    if (!filtered) {
      $('#exampleFiltering').slick('slickFilter', ':even');
      $(this).text('不过滤');
      filtered = true;
    } else {
      $('#exampleFiltering').slick('slickUnfilter');
      $(this).text('过滤');
      filtered = false;
    }
  });
})(document, window, jQuery);
